home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing;
-
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Image;
- import java.awt.Rectangle;
- import java.awt.Toolkit;
- import java.awt.image.ImageObserver;
- import java.util.Enumeration;
- import java.util.Hashtable;
- import java.util.Vector;
-
- public class RepaintManager {
- WorkRequest doWorkRequest = new WorkRequest(this);
- Hashtable dirtyComponents = new Hashtable();
- Vector invalidComponents;
- boolean doubleBufferingEnabled = true;
- Image doubleBuffer;
- Dimension doubleBufferMaxSize = Toolkit.getDefaultToolkit().getScreenSize();
- private static final Object repaintManagerKey;
- static Class class$com$sun$java$swing$RepaintManager;
-
- static {
- Class var10000 = class$com$sun$java$swing$RepaintManager;
- if (var10000 == null) {
- try {
- var10000 = Class.forName("com.sun.java.swing.RepaintManager");
- } catch (ClassNotFoundException var0) {
- throw new NoClassDefFoundError(((Throwable)var0).getMessage());
- }
-
- class$com$sun$java$swing$RepaintManager = var10000;
- }
-
- repaintManagerKey = var10000;
- }
-
- public void addDirtyRegion(JComponent c, int x, int y, int w, int h) {
- if (w > 0 && h > 0 && ((Component)c).isShowing()) {
- synchronized(this){}
-
- try {
- if (this.dirtyComponents == null) {
- this.dirtyComponents = new Hashtable();
- this.dirtyComponents.put(c, new Rectangle(x, y, w, h));
- } else {
- Rectangle r = (Rectangle)this.dirtyComponents.get(c);
- if (r == null) {
- this.dirtyComponents.put(c, new Rectangle(x, y, w, h));
- } else {
- SwingUtilities.computeUnion(x, y, w, h, r);
- }
- }
- } catch (Throwable var9) {
- throw var9;
- }
-
- if (!this.doWorkRequest.isPending) {
- this.queueWorkRequest(c);
- }
-
- }
- }
-
- public synchronized void addInvalidComponent(JComponent invalidComponent) {
- Component validateRoot = null;
-
- for(Component c = invalidComponent; c != null; c = c.getParent()) {
- if (c instanceof CellRendererPane) {
- return;
- }
-
- if (c instanceof JComponent && ((JComponent)c).isValidateRoot()) {
- validateRoot = c;
- break;
- }
- }
-
- if (validateRoot != null && validateRoot.isShowing()) {
- if (this.invalidComponents == null) {
- this.invalidComponents = new Vector();
- } else {
- int n = this.invalidComponents.size();
-
- for(int i = 0; i < n; ++i) {
- if (validateRoot == (Component)this.invalidComponents.elementAt(i)) {
- return;
- }
- }
- }
-
- this.invalidComponents.addElement(validateRoot);
- if (!this.doWorkRequest.isPending) {
- this.queueWorkRequest(invalidComponent);
- }
- }
-
- }
-
- void collectDirtyComponents(Hashtable dirtyComponents, JComponent dirtyComponent, Vector roots) {
- Component rootDirtyComponent = dirtyComponent;
- Component component = dirtyComponent;
- Rectangle cBounds = dirtyComponent._bounds;
- int rootDx = 0;
- int dx = 0;
- int rootDy = 0;
- int dy = 0;
- Rectangle tmp = new Rectangle((Rectangle)dirtyComponents.get(dirtyComponent));
- SwingUtilities.computeIntersection(0, 0, cBounds.width, cBounds.height, tmp);
- if (!tmp.isEmpty()) {
- if (dirtyComponent.isOpaque()) {
- }
-
- while(true) {
- Component parent = ((Component)component).getParent();
- if (parent == null || !(parent instanceof JComponent)) {
- if (dirtyComponent != rootDirtyComponent) {
- tmp.setLocation(tmp.x + rootDx - dx, tmp.y + rootDy - dy);
- Rectangle r = (Rectangle)dirtyComponents.get(rootDirtyComponent);
- SwingUtilities.computeUnion(tmp.x, tmp.y, tmp.width, tmp.height, r);
- }
-
- if (!roots.contains(rootDirtyComponent)) {
- roots.addElement(rootDirtyComponent);
- }
-
- return;
- }
-
- component = parent;
- if (((JComponent)parent).isOpaque()) {
- }
-
- dx += cBounds.x;
- dy += cBounds.y;
- tmp.setLocation(tmp.x + cBounds.x, tmp.y + cBounds.y);
- cBounds = ((JComponent)parent)._bounds;
- tmp = SwingUtilities.computeIntersection(0, 0, cBounds.width, cBounds.height, tmp);
- if (tmp.isEmpty()) {
- return;
- }
-
- if (dirtyComponents.get(parent) != null) {
- rootDirtyComponent = parent;
- rootDx = dx;
- rootDy = dy;
- }
- }
- }
- }
-
- public static RepaintManager currentManager(JComponent comp) {
- RepaintManager result = (RepaintManager)SwingUtilities.appContextGet(repaintManagerKey);
- if (result == null) {
- result = new RepaintManager();
- SwingUtilities.appContextPut(repaintManagerKey, result);
- }
-
- return result;
- }
-
- public Rectangle getDirtyRegion(JComponent aComponent) {
- Rectangle r = null;
- synchronized(this){}
-
- try {
- if (this.dirtyComponents != null) {
- r = (Rectangle)this.dirtyComponents.get(aComponent);
- }
- } catch (Throwable var5) {
- throw var5;
- }
-
- return r == null ? new Rectangle(0, 0, 0, 0) : new Rectangle(r);
- }
-
- public Dimension getDoubleBufferMaximumSize() {
- return this.doubleBufferMaxSize;
- }
-
- public Image getOffscreenBuffer(Component c, int proposedWidth, int proposedHeight) {
- int width;
- if (proposedWidth > this.doubleBufferMaxSize.width) {
- width = this.doubleBufferMaxSize.width;
- } else {
- width = proposedWidth;
- }
-
- int height;
- if (proposedHeight > this.doubleBufferMaxSize.height) {
- height = this.doubleBufferMaxSize.height;
- } else {
- height = proposedHeight;
- }
-
- if (this.doubleBuffer != null && (this.doubleBuffer.getWidth((ImageObserver)null) < width || this.doubleBuffer.getHeight((ImageObserver)null) < height)) {
- this.doubleBuffer = null;
- }
-
- if (this.doubleBuffer == null) {
- this.doubleBuffer = c.createImage(width, height);
- }
-
- return this.doubleBuffer;
- }
-
- public boolean isCompletelyDirty(JComponent aComponent) {
- Rectangle r = this.getDirtyRegion(aComponent);
- return r.width == Integer.MAX_VALUE && r.height == Integer.MAX_VALUE;
- }
-
- public boolean isDoubleBufferingEnabled() {
- return this.doubleBufferingEnabled;
- }
-
- public void markCompletelyClean(JComponent aComponent) {
- synchronized(this){}
-
- try {
- if (this.dirtyComponents != null) {
- this.dirtyComponents.remove(aComponent);
- }
- } catch (Throwable var4) {
- throw var4;
- }
-
- }
-
- public void markCompletelyDirty(JComponent aComponent) {
- this.addDirtyRegion(aComponent, 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE);
- }
-
- public void paintDirtyRegions() {
- Hashtable tmpDirtyComponents;
- synchronized(this) {
- if (this.dirtyComponents == null) {
- return;
- }
-
- tmpDirtyComponents = this.dirtyComponents;
- this.dirtyComponents = null;
- }
-
- int count = tmpDirtyComponents.size();
- if (count != 0) {
- Vector roots = new Vector(count);
- Enumeration keys = tmpDirtyComponents.keys();
-
- while(keys.hasMoreElements()) {
- JComponent dirtyComponent = (JComponent)keys.nextElement();
- this.collectDirtyComponents(tmpDirtyComponents, dirtyComponent, roots);
- }
-
- count = roots.size();
-
- for(int i = 0; i < count; ++i) {
- JComponent var11 = (JComponent)roots.elementAt(i);
- Rectangle rect = (Rectangle)tmpDirtyComponents.get(var11);
- Rectangle localBounds = ((Component)var11).getBounds();
- localBounds.x = localBounds.y = 0;
- rect = rect.intersection(localBounds);
- var11.paintImmediately(rect.x, rect.y, rect.width, rect.height);
- }
-
- }
- }
-
- void queueWorkRequest(JComponent target) {
- if (!this.doWorkRequest.isPending) {
- synchronized(this){}
-
- try {
- this.doWorkRequest.isPending = true;
- this.doWorkRequest.component = target;
- SwingUtilities.invokeLater(this.doWorkRequest);
- } catch (Throwable var4) {
- throw var4;
- }
- }
-
- }
-
- public synchronized void removeInvalidComponent(JComponent component) {
- if (this.invalidComponents != null) {
- int index = this.invalidComponents.indexOf(component);
- if (index != -1) {
- this.invalidComponents.removeElementAt(index);
- }
- }
-
- }
-
- public static void setCurrentManager(RepaintManager aRepaintManager) {
- if (aRepaintManager != null) {
- SwingUtilities.appContextPut(repaintManagerKey, aRepaintManager);
- } else {
- SwingUtilities.appContextRemove(repaintManagerKey);
- }
-
- }
-
- public void setDoubleBufferingEnabled(boolean aFlag) {
- this.doubleBufferingEnabled = aFlag;
- if (!this.doubleBufferingEnabled) {
- this.doubleBuffer = null;
- }
-
- }
-
- public void setDoubleBufferMaximumSize(Dimension d) {
- this.doubleBufferMaxSize = d;
- if (this.doubleBuffer != null && (this.doubleBuffer.getWidth((ImageObserver)null) > d.width || this.doubleBuffer.getHeight((ImageObserver)null) > d.height)) {
- this.doubleBuffer = null;
- }
-
- }
-
- public synchronized String toString() {
- StringBuffer sb = new StringBuffer();
- if (this.dirtyComponents != null) {
- sb.append("" + this.dirtyComponents);
- }
-
- return sb.toString();
- }
-
- public void validateInvalidComponents() {
- Vector ic;
- synchronized(this) {
- if (this.invalidComponents == null) {
- return;
- }
-
- ic = this.invalidComponents;
- this.invalidComponents = null;
- }
-
- int n = ic.size();
-
- for(int i = 0; i < n; ++i) {
- ((Component)ic.elementAt(i)).validate();
- }
-
- }
- }
-